VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Registry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long

Private Const ERROR_SUCCESS = 0&

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003

Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_LENGTH = &H100
Private Const VALUE_LENGTH = &H400
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = _
    ((STANDARD_RIGHTS_ALL Or _
    KEY_QUERY_VALUE Or _
    KEY_SET_VALUE Or _
    KEY_CREATE_SUB_KEY Or _
    KEY_ENUMERATE_SUB_KEYS Or _
    KEY_NOTIFY Or KEY_CREATE_LINK) And _
    (Not SYNCHRONIZE))
    
Public Function EnumKeys(strSection As String, keyName As String) As Variant
Dim hKey As Long
Dim keyNames As Variant
Dim section As Long
Dim i As Long

    'FORCE IT TO TURN VARIANT INTO ARRAY: fuuuuck
    ReDim keyNames(0)

    ' Convert from string to the section code
    section = GetSection(strSection)

    ' Open the key.
    If RegOpenKeyEx(section, keyName, 0, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
        Exit Function
    End If

    ' Enumerate
    keyName = Space(KEY_LENGTH)
    While RegEnumKey(hKey, i, keyName, KEY_LENGTH) = ERROR_SUCCESS
            ReDim Preserve keyNames(i) '<---- NOT GOOD ENOUGH. WON'T FORCE IT TO BE ARRAY FIRST TIME
                                        'THATS WHY WE REDIM ABOVE
            keyNames(i) = Left(keyName, InStr(keyName, vbNullChar) - 1)
            keyName = Space(KEY_LENGTH)
            i = i + 1
    Wend

    ' Close the key.
    RegCloseKey (hKey)
    
    EnumKeys = keyNames
End Function

Public Function EnumValues(strSection As String, keyName As String) As Variant
Dim hKey As Long
Dim valueName As String
Dim valueNames As Variant
Dim valueType As Long
Dim section As Long
Dim valueData(1 To VALUE_LENGTH) As Byte
Dim i As Long

    'FORCE IT TO TURN VARIANT INTO ARRAY: fuuuuck
    ReDim valueNames(0)

    ' Convert from string to the section code
    section = GetSection(strSection)

    ' Open the key.
    If RegOpenKeyEx(section, keyName, 0, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
        Exit Function
    End If

    ' Enumerate
    valueName = Space(VALUE_LENGTH)
    While RegEnumValue(hKey, i, valueName, VALUE_LENGTH, 0, valueType, valueData(1), VALUE_LENGTH) = ERROR_SUCCESS
        ReDim Preserve valueNames(i)
        valueNames(i) = Left(valueName, InStr(valueName, vbNullChar) - 1)
        valueName = Space(VALUE_LENGTH)
        i = i + 1
    Wend

    ' Close the key.
    RegCloseKey (hKey)
    
    EnumValues = valueNames
End Function

Public Function EnumTypes(strSection As String, keyName As String) As Variant
Dim hKey As Long
Dim valueName As String
Dim valueTypes As Variant
Dim valueType As Long
Dim section As Long
Dim valueData(1 To VALUE_LENGTH) As Byte
Dim i As Long

    'FORCE IT TO TURN VARIANT INTO ARRAY: fuuuuck
    ReDim valueTypes(0)

    ' Convert from string to the section code
    section = GetSection(strSection)

    ' Open the key.
    If RegOpenKeyEx(section, keyName, 0, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
        Exit Function
    End If

    ' Enumerate
    valueName = Space(VALUE_LENGTH)
    While RegEnumValue(hKey, i, valueName, VALUE_LENGTH, 0, valueType, valueData(1), VALUE_LENGTH) = ERROR_SUCCESS
        ReDim Preserve valueTypes(i)
        valueTypes(i) = valueType
        valueName = Space(VALUE_LENGTH)
        i = i + 1
    Wend

    ' Close the key.
    RegCloseKey (hKey)
    
    EnumTypes = valueTypes
End Function

Private Function GetSection(section As String) As Long
Select Case section
Case "HKCR"
    GetSection = HKEY_CLASSES_ROOT
Case "HKCU"
    GetSection = HKEY_CURRENT_USER
Case "HKCC"
    GetSection = HKEY_CURRENT_CONFIG
Case "HKLM"
    GetSection = HKEY_LOCAL_MACHINE
Case "HKU"
    GetSection = HKEY_USERS
End Select
End Function
